<style>
    .required-tip{
        display: inline-block;
        color:#f00505;
        margin-left: 5px;
        font-size: 20px;
        padding-top: 5px;
    }
</style>

<div style="padding:20px">
    <form class="layui-form" action="">
    <input type="hidden" name="id" value="{$admin.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">登录账户<span class="required-tip">*</span></label>
        <div class="layui-input-block">
          <input type="text" name="username" value="{$admin.username}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">手机号<span class="required-tip">*</span></label>
        <div class="layui-input-block">
          <input type="number" name="phone" value="{$admin.phone}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">角色权限</label>
        <div class="layui-input-block">
          {if condition="!empty($admin.auth_ids)"}
            {volist name='auth_list' id='vo'}
                <input type="radio" name="auth_ids" value="{$vo.id}" title="{$vo.title}" {if condition="$vo.id eq $admin.auth_ids"} checked {/if}>
            {/volist}
          {/if}
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">普通文本域</label>
        <div class="layui-input-block">
          <textarea placeholder="请输入内容" class="layui-textarea" name="remark">{$admin.remark}</textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    </form>
</div>

<script>

layui.use(['form'], function(){
  var form = layui.form;
  var layer = layui.layer;
  var laydate = layui.laydate;
  var util = layui.util;
  
  // 自定义验证规则
  form.verify({
    pass: function(value) {
      if (!/(.+){6,12}$/.test(value)) {
        return '密码必须 6 到 12 位';
      }
    }
  });
  
  // 指定开关事件
  form.on('switch(switchTest)', function(data){
    layer.msg('开关 checked：'+ (this.checked ? 'true' : 'false'), {
      offset: '6px'
    });
    layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
  });
  
  // 提交事件
  form.on('submit(demo1)', function(data){
    var field = data.field; // 获取表单字段值
    // 显示填写结果，仅作演示用

    // layer.alert(JSON.stringify(field), {
    //   title: '当前填写的字段值'
    // });

    // 此处可执行 Ajax 等操作

    $.post("{:url('system.admin/edit')}",data.field,function(res){
      if(res.code==1){
        layer.msg(res.msg,function(){
          window.parent.refresh()
          //layer.close(window.parent.layerIndex)
        })
      }

      if(res.code==0){
        layer.msg(res.msg)
      }


    })



    // …
    return false; // 阻止默认 form 跳转
  });

});
</script>
 